Created: 2022-07-10
Tags: #fleeting
Sometimes bugs in your code that you don't see visually like possible memory leaks exists.
int main(void)
{
char *s = malloc(2); // Only accepts 2 bytes of char
s[0] = 'H';
s[1] = 'I';
s[2] = '!';
s[3] = '\0';
}
// This code will still run despite it having possible memory leak.
Valgrind is a tool to help you determine memory bugs.
What does Memory Error mean
Invalid read/write of size XUse of uninitialised valueor -> Conditional jump or move depends on uninitialised value(s)
First One: Program reads the value of an empty memory location
Second One: Specifically occured in if/for/while
Solution:
-> Explicitly Initialize all of your variables!!!
If you want int to be 0,
or pointer to be NULL
then make it so. Don't assign an empty thing!
Memory Leak